package com.uton.rfidcontroller.viewmodel.activity_model;

import android.databinding.ObservableField;

import com.uton.rfidcontroller.common.interfaces.INetController;
import com.uton.rfidcontroller.common.interfaces.IPublicController;
import com.uton.rfidcontroller.common.net.RetrofitFactory;
import com.uton.rfidcontroller.model.CarListModel;
import com.uton.rfidcontroller.viewmodel.base.BaseViewModel;

import java.util.HashMap;
import java.util.List;

/**
 * Created by 王家宝 on 2017/9/26.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class WriteActivityViewModel extends BaseViewModel implements IPublicController.ILoadingController {

    private String carDealerId;
    public final ObservableField<String> preWrittenCount = new ObservableField<>("");


    public WriteActivityViewModel(String carDealerId, String count) {
        this.carDealerId = carDealerId;
        preWrittenCount.set(count);
        beginInit();
        refreshData();
    }

    @Override
    public void refreshData() {
        showDialog();
        HashMap<String, Object> tempData = new HashMap<>();
        tempData.put("carDealerId", carDealerId);
        go(RetrofitFactory.getInstance().carListWriteIn(tempData), new INetController<List<CarListModel>>() {
            @Override
            public void onSuccess(List<CarListModel> response) {
                doOnRequestComplete(response);
                dismissDialog();
            }

            @Override
            public void onError() {
                dismissDialog();
            }

            @Override
            public void onComplete() {
                doOnComplete();
                dismissDialog();
            }
        });
    }

    public abstract void beginInit();

    public abstract void doOnComplete();

    public abstract void doOnRequestComplete(List<CarListModel> data);

    public abstract void showCarDealerDetail();


}
